Purpose
Read an ALV grid

Solution
Use a SAP standard function to copy the content of the ALV grid to the Windows clipboard; then read the clipboard via CopyText.

  • The ALV Grid Control (ALV = SAP List Viewer) is used in a large range of SAP transactions
  • Alternative ways to read the grid values are offered by the command GetGridValues or by the  Native Control Interface
Example
We read PM operations via IW37N and display them in a SAP GUI table:





GuiXT script

GuiXT
Pushbutton (toolbar) "Load operations" _
	      process="load_operations.txt"

 if not V[operations.rowcount]
  CreateStructure V[operation] aufnr ktext vornr ltxa1 arbpl sttxt
  CreateTable V[operations] include=V[operation]  
endif

Table (2,2) (29,131) name="operations"  _
  fixedColumns=6 title="&V[operations.rowcount] operations selected"

Column "Order" name="aufnr" size=8
Column "Description" name="ktext" size=40
Column "Operation" name="vornr" size=8
Column "Short text" name="ltxa1" size=40
Column "Workplace" name="arbpl" size=10
Column "Syst.State" name="sttxt" size=20

 


Input script load_operations.txt

GuiXT
// read operation via transaction IW37N
Enter "/niw37n"

//  Selection of Orders and Operations
Screen RI_ORDER_OPERATION_LIST.1000
  
  // Sample selection criteria
  Set F[Period]        "25.02.2000"  
  Set F[Period to]     "31.12.2025"
  
  Enter "=S_TAB9"      	// goto TAB Miscellaneous
  
Screen RI_ORDER_OPERATION_LIST.1000
  Title "Please wait... Reading operations"
  
  // set GuiXT Layout
  Set F[Layout] 	"/GUIXT"
  
  Enter "/8"           // Execute
  
  
  
// List of Orders and Operations
Screen SAPLSLVC_FULLSCREEN.0500
  
  Title "Please wait... Reading operations"
  
  Enter "==%PC"   // Use command "==%PC", not "=%PC" !
  
  
  // Alternative:
  //  Enter "/Menu=1,11,3"  
  
  
  
// popup screen for output selection
Screen   SAPLSPO5.0110
  
  // select "clipboard" option
  Set R[In the clipboard] "X"
  
  Enter
  
  
Screen SAPLSLVC_FULLSCREEN.0500
  
  Title "Please wait... Reading operations"
  
  // read the clipboard into a text variable
  CopyText toText="temp"  -fromClipboard
  
  // restore the clipboard
  CopyText fromText="cbbackup"  -toClipboard
  
  // clear table operations
  Clear V[operations]
  
  // text lines, skip title and header
  Set V[k] 5
  
  label next_line
  
  Set V[k] &V[k] + 1
  
  CopyText fromText="temp" toString="s"  line="&V[k]"
  
  if Q[ok]
    
    CopyText fromString="s" toText="cells"
    
    CopyText fromText="cells" toString="operation.aufnr" _
      line=3 delimiter="|"
    
    CopyText fromText="cells" toString="operation.ktext" _
      line=4 delimiter="|"
    
    CopyText fromText="cells" toString="operation.vornr" _
      line=5 delimiter="|" 
    
    CopyText fromText="cells" toString="operation.ltxa1" _
      line=6 delimiter="|" 
    
    CopyText fromText="cells" toString="operation.arbpl" _
      line=7 delimiter="|"
    
    CopyText fromText="cells" toString="operation.sttxt" _
      line=8 delimiter="|"
    
    // append new table row if all 6 columns found
    if Q[ok] 
      AppendRow V[operation] table=V[operations]  
    endif
    
    goto next_line
  endif
   
  // return to calling transaction
  Return
  

Components
InputAssistant